/**
 * @author Patrick
 * Sub-class of CompositeType which is a sub-class of Type. 
 * Contains the name and size of the CompositeType of Struct.
 * More will be updated soon
 */
public class StructType extends CompositeType{
	
	/*
	 * Default ctor that creates an IntType object with
	 * name "struct" and the size (bytes) will be the sum of the size of element.
	 */
	private Scope scope; // reference to the struct on sym table
	private String baseName;
	/*
	 * Whenever we have a structdef:
	 * Typedef type will be StructType
	 * scope holds on to a reference to the scope we started with the structdef {}
	 * insert and check as normal(as the same as scope) in structdef
	 */
	
	public StructType(String strName) {
		super(strName, 0);
	}
	public StructType(String strName, int size) {
		super(strName, size); // 8 will be changed later
	}
	
	public StructType(String strName, Scope scope, int size) {
		this(strName, size); // 8 will be changed later
		setScope(scope);
	}

	@Override
	public boolean isStructType() { 
		return true; 
	}
	
	public Scope getScope() {
		return scope;
	}
	public void setScope(Scope scope) {
		this.scope = scope;
	}
	@Override
	public boolean isAssignableTo(Type t) {
		return isEquivalentTo(t);
	}
	
	@Override
	public boolean isEquivalentTo(Type t) {
		if(t.isStructType()) {
			if(getBaseName().equals(((StructType)t).getBaseName())) {
				return true;
			}
		}
		return false;
	}
	public String getBaseName() {
		return baseName;
	}
	public void setBaseName(String baseName) {
		this.baseName = baseName;
	}

}
